<?php
//header("Content-type:application/json; charset=UTF-8"); 
include "../connect.php";
$mongoConn = new Mongo();
$date_m=array("","มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม",);
if($_POST['act']=='news'){
$id_new =$_POST["c_id"];
$data = $mongoConn->smmweb->news->findOne(array('news_id' => $id_new));
$c_view = $_POST['c_view']+1;
$sql_detail =mysql_query("
SELECT c_id,c_category,c_public,c_title,c_post_on,c_intro,c_image,c_post_editor,c_intro_2,c_reply,
(select c_display_name from smm_members where c_id = c_post_editor)n_user
from  smm_news  where c_id=".$id_new." ");
$json_data[num_new]=mysql_num_rows($sql_detail);
$rs=mysql_fetch_assoc($sql_detail);
    $y=date("Y",strtotime($rs['c_post_on']))+543;
    $m=$date_m[date("n",strtotime($rs['c_post_on']))];
	$divdata='<div id="content_data_woman"><div id="title_w">'.$rs[c_title].'</div>
	<div id="text_n"><span id="post_editor">เขียนโดย : <b>'.$rs[n_user].'</b><br>เขียนเมื่อ : <b>'.date("d $m $y เวลา H:i น.",strtotime($rs[c_post_on])).'</b><br>อ่านไปแล้ว :<b> '.$c_view.'</b> ครั้ง,&nbsp;<b>'.$rs[c_reply].'</b>&nbsp;ความคิดเห็น</span></div><div id="add_this">
<!--<div class="addthis_toolbox addthis_default_style addthis_32x32_style">
<a class="addthis_button_preferred_1"></a>
<a class="addthis_button_preferred_2"></a>
<a class="addthis_button_preferred_3"></a>
<a class="addthis_button_preferred_4"></a>
<a class="addthis_button_compact"></a>
<a class="addthis_counter addthis_bubble_style"></a>
</div>
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4e3f66c951ee96c5"></script>-->
</div>
	<br><br><img src="'.str_replace("small","big",$rs[c_image]).'" width="632"><div class="c_intro">'.$rs[c_intro].'&nbsp;'.$rs[c_intro_2].'</div><span>'.htmlspecialchars_decode($data['news_desc']).'</span></div>';
$json_data[pro_title]=$divdata;

$sql_other=mysql_query("
SELECT na.c_id,na.c_section,n.c_id,n.c_category,n.c_public,n.c_title,n.c_post_on,n.c_image
from smm_news_category na left join smm_news n on na.c_id = n.c_category 
where  na.c_section='woman' and n.c_public='1' order by rand() DESC limit 0,6");

while($rs=mysql_fetch_array($sql_other)){
	$data_other[]="<div class=data_other><div class=data_woman_other><span class=img_healty><a href='/detail_news.php?c_id=".$rs['c_id']."' target='_blank'><img src=".$rs[c_image]." width='100' height='67' title='".$rs['c_title']."' border='0'></a></span></div><div class=text_other><a href='/detail_news.php?c_id=".$rs['c_id']."' target='_blank' title='".$rs['c_title']."'>".iconv_substr($rs[c_title],0,27,"utf-8")."...</a></div></div></div>";
}
$datas=implode($data_other);
$json_data[data_other]=$datas;

echo json_encode($json_data);

$sql="UPDATE smm_news SET c_view = '".$c_view."' where c_id='".$_POST[c_id]."' ";
$db = mysql_query($sql);
exit;
}
if($_POST['act']=='article'){
$id_article =$_POST["c_id"];
$c_view = $_POST['c_view']+1;
$data = $mongoConn->smmweb->article_desc->findOne(array('c_article_id' => $id_article));
$sql_detail =mysql_query("
SELECT c_id,c_category,c_public,c_title,c_desc,c_post_on,c_intro,c_image,c_post_editor,c_intro_2,c_reply,
(select c_display_name from smm_members where c_id = c_post_editor)n_user
from  smm_article  where c_id=".$id_article." ");
$json_data[num_article]=mysql_num_rows($sql_detail);
$rs=mysql_fetch_assoc($sql_detail);
    $y=date("Y",strtotime($rs['c_post_on']))+543;
    $m=$date_m[date("n",strtotime($rs['c_post_on']))];
	$divdata='<div id="content_data_woman"><div id="title_w">'.$rs[c_title].'</div><div id="text_n"><span id="post_editor">เขียนโดย : <b>'.$rs[n_user].'</b><br>เขียนเมื่อ :<b> '.date("d $m $y เวลา H:i น.",strtotime($rs[c_post_on])).'</b><br>อ่านไปแล้ว : <b>'.$c_view.' </b>ครั้ง,&nbsp;<b>'.$rs[c_reply].'</b>&nbsp;ความคิดเห็น</span></div><div id="add_this">
<!--<div class="addthis_toolbox addthis_default_style addthis_32x32_style">
<a class="addthis_button_preferred_1"></a>
<a class="addthis_button_preferred_2"></a>
<a class="addthis_button_preferred_3"></a>
<a class="addthis_button_preferred_4"></a>
<a class="addthis_button_compact"></a>
<a class="addthis_counter addthis_bubble_style"></a>
</div>
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4e3f66c951ee96c5"></script>-->
</div> 
	<br><br><img src="'.str_replace("small","big",$rs[c_image]).'" width="632"><div class="c_intro">'.$rs[c_intro].'&nbsp;'.$rs[c_intro_2].'</div><div>'.htmlspecialchars_decode($data['c_desc']).'</div></div>';

$json_data[pro_title]=$divdata;
$sql_other=mysql_query("
SELECT ca.c_id,ca.c_section,a.c_id,a.c_category,a.c_public,a.c_title,a.c_post_on,a.c_image
from smm_article_category ca left join smm_article a on ca.c_id = a.c_category 
where  ca.c_section='woman' and a.c_public='1' order by rand() DESC limit 0,6");

while($rs=mysql_fetch_array($sql_other)){
	$data_other[]="<div class=data_other><div class=data_woman_other><span class=img_healty><a href='/detail_article.php?c_id=".$rs['c_id']."' target='_blank'><img src=".$rs[c_image]." width='100' height='67' title='".$rs['c_title']."' border='0'></a></span></div><div class=text_other><a href='/detail_article.php?c_id=".$rs['c_id']."' target='_blank' title='".$rs['c_title']."'>".iconv_substr($rs[c_title],0,27,"utf-8")."...</a></div></div></div>";
}
$datas=implode($data_other);
$json_data[data_other]=$datas;
echo json_encode($json_data);
$sql="UPDATE smm_article SET c_view = '".$c_view."' where c_id='".$_POST[c_id]."' ";
$db = mysql_query($sql);
 
//$m->close();
exit;


}



?>